<?php

namespace App\Http\Models;

use Illuminate\Database\Eloquent\Model;

class ProductModel extends Model
{
	const STATUS_ACTIVE = 1;

	protected $connection = 'db_main';

	protected $table = 'wp_sdk_member_product';

	public $timestamps = false;

    public static function info($key, $level_type = 1)
    {
        return self::where(["status" => self::STATUS_ACTIVE, "user_level_type" => $level_type, "key" => $key])->first();
    }

    /*获取某个付费产品所需支付的金额*/
    public static function getUnitPriceBykey($name)
    {
        $productInfo = self::info($name);
        $unitPrice = $productInfo->month_price ? $productInfo->month_price : 0;
        $unitPrice = $unitPrice>$productInfo->discount ? abs($unitPrice-$productInfo->discount) : 0;
        return  $unitPrice;
    }
}

